package com.bangcommunity.bbframe.sdm.web.shiro.session;

import com.bangcommunity.bbframe.sdm.web.exception.RestConf;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.SessionFactory;
import org.springframework.stereotype.Component;

/**
 * 为了生成appSession而写的factory
 * 
 * @author tanghc
 *
 */
@Component
public class SdmAppSessionFactory implements SessionFactory {

    @Override
    public Session createSession(SessionContext initData) {
        if (initData != null) {
            String host = initData.getHost();
            if (host != null) {
                SdmAppSession appSession = new SdmAppSession(host, RestConf.appSessionLoginExpireSec);
                return appSession;
            }
        }
        SdmAppSession appSession = new SdmAppSession(RestConf.appSessionLoginExpireSec);
        return appSession;
    }
}
